from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny

from aijia_project.utils.Error_statuscode import ErrorCode
from houses.models import Area
from houses.serializers.areas import AreaSerializer


class AreaListView(GenericAPIView):
    """获取所有城区信息"""
    serializer_class = AreaSerializer
    queryset = Area.objects.all()

    # 允许所有用户访问
    permission_classes = (AllowAny,)

    def get(self, request):
        queryset = self.get_queryset()
        serializer = self.get_serializer(queryset, many=True)

        return Response({
            "errmsg": "获取成功",
            "errno": ErrorCode.OK,
            "data": serializer.data
        })
